﻿
Const ET_NO_ENTITY:Int	= 0
Const ET_ENTITY:Int		= 1
Const ET_CAMERA:Int		= 2
Const ET_LIGHT:Int		= 3
Const ET_SCENENODE:Int	= 4
Const ET_MATERIAL:Int	= 5
Const ET_TECHNIQUE:Int	= 6
Const ET_MESH:Int		= 7


' Transformationspace
Const TS_LOCAL:Int		= 1
Const TS_PARENT:Int		= 2
Const TS_WORLD:Int		= 3


Type BaseObject
	Field _ptr:Byte ptr
	Field _typ:Int
		
rem
bbdoc: Returns the name of this object. 
endrem
	Method getName:String()
		Return o_getName(Self._ptr)
	End Method
	
rem
bbdoc: Returns the type name of this object. 
endrem
	Method getType:String()
		Local result:String = ""
		Select Self._typ
			Case ET_NO_ENTITY	; result = "NO ENTITY"
			Case ET_SCENENODE	; result = "Scenenode"
			Default				; result = o_getType(Self._ptr)
		End Select
		
		Return result
	End Method
	
	
	Method getEntityType:Int()
		Return Self._typ
	End Method
	
	
	Function getFromHandle:BaseObject(hnd:Int)
		Return BaseObject(HandleToObject(hnd))
	End Function
End Type

Type Root Extends BaseObject
	Global _entity_count:Int
	Field Compositor_Manager:CompositorManager
	
	
	Method New()
		Self.Compositor_Manager = New CompositorManager
	End Method
	
	
	Function genName:String(prefix:String = "entity_")
		Root._entity_count:+ 1
		Return prefix + String(Root._entity_count)
	End Function
	
rem
bbdoc: Constructor.
about:
	<table cellpadding="4" cellspacing="4" border="0">
	<tr>
		<td>
			<i>pluginFileName</i>
		</td>
		<td>
			The file that contains plugins information. Defaults to "plugins.cfg", may be left blank to ignore.
		</td>
	</tr>
	<tr>
		<td>
			<i>configFileName</i>
		</td>
		<td>
			The file that contains the configuration to be loaded. Defaults to "ogre.cfg", may be left blank to load nothing.
		</td>
	</tr>
	<tr>
		<td>
			<i>logFileName</i>
		</td>
		<td>
			The logfile to create, defaults to Ogre.log, may be left blank if you've already set up LogManager and Log yourself 
		</td>
	</tr>
	</table>
endrem
	Function Create:Root(plugins:String = "plugins.cfg", config:String = "ogre.cfg", logfile:String = "ogre.log", manual:Byte = False)
		Local mroot:Root = New Root
		mroot._ptr = o_newRoot(plugins.ToCString(), config.ToCString(), logfile.ToCString(), manual)
		mroot._typ = ET_NO_ENTITY
		
		Return mroot
	End Function
	
rem
bbdoc: Checks for saved video/sound/etc settings.
returns: If a valid configuration was found, true is returned. If there is no saved configuration, or if the system failed with the last config settings, false is returned. 
about: This method checks to see if there is a valid saved configuration from a previous run. If there is, the state of the system 
will be restored to that configuration.<br>
endrem
	Method restoreConfig:Byte()
		Return o_restoreConfig(Self._ptr)
	End Method
	
rem
bbdoc: Displays a dialog asking the user to choose system settings.
returns:     If the user clicked 'Ok', true is returned.<br>If they clicked 'Cancel' (in which case the app should strongly consider terminating), false is returned. 
about: This method displays the default dialog allowing the user to choose the rendering system, video mode etc. If there is are any settings saved already, they will be restored automatically before displaying the dialogue. When the user accepts a group of settings, this will automatically call Root::setRenderSystem, RenderSystem::setConfigOption and Root::saveConfig  with the user's choices. This is the easiest way to get the system configured. 
endrem
	Method showConfigDialog:Byte()
		Return o_showConfigDialog(Self._ptr)
	End Method
	
rem
bbdoc: Initialises the renderer. 
returns: Type <i>RenderWindow</i>, if requested, otherwise NULL.
about: This method can only be called after a renderer has been selected with Root::setRenderSystem, and it will initialise the 
selected rendering system ready for use. 
<p><i>autoCreateWindow</i>If true, a rendering window will automatically be created (saving a call to Root::createRenderWindow). The window will be created based on the options currently set on the render system. </p>
endrem
	Method initialise:RenderWindow(autoCreateWindow:Byte = True, windowTitle:String = "Ogre3D", customCapabilities:String = "")
		Local win:RenderWindow = New RenderWindow
		win._ptr = o_initialise(Self._ptr, autoCreateWindow, windowTitle.ToCString(), customCapabilities.ToCString())
		win._typ = ET_NO_ENTITY
		
		Return win
	End Method
	
rem
bbdoc: Shuts down the system manually. 
endrem
	Method Shutdown()
		o_freeRoot(Self._ptr)
	End Method
	
rem
bbdoc: Saves the details of the current configuration. 
about: Stores details of the current configuration so it may be restored later on. 
endrem
	Method saveConfig()
		o_saveConfig(Self._ptr)
	End Method
	
rem
bbdoc: Retrieve a pointer to the render system by the given name. 
returns: A object from Type <i>RenderSystem</i>, NULL if no found. 
about: Parameters: Name of the render system intend to retrieve. 
endrem
	Method getRenderSystemByName:RenderSystem(rendersystem_name:String)
		Local rs:RenderSystem = New RenderSystem
		rs._ptr = o_getRenderSystemByName(Self._ptr, rendersystem_name.ToCString())
		rs._typ = ET_NO_ENTITY
		
		Return rs
	End Method
	
rem
bbdoc: Sets the rendering subsystem to be used.
about: This method indicates to OGRE which rendering system is to be used (e.g. Direct3D, OpenGL etc). This is called 
automatically by the default config dialog, and when settings are restored from a previous configuraion. If used manually 
it could be used to set the renderer from a custom settings dialog. Once this has been done, the renderer can be initialised 
using Root::initialise.<p>This method is also called by render systems if they are initialised directly.</p>
endrem
	Method setRenderSystem(rs:RenderSystem)
		o_setRenderSystem(Self._ptr, rs._ptr)
	End Method
	
	
rem
bbdoc: Retrieve a pointer to the currently selected render system. 
endrem
	Method getRenderSystem:RenderSystem()
		Local rs:RenderSystem = New RenderSystem
		rs._ptr = o_getRenderSystem(Self._ptr)
		rs._typ = ET_NO_ENTITY
		
		Return rs
	End Method
	
rem
bbdoc: Creates a new rendering window.
about: This method creates a new rendering window as specified by the paramteters. The rendering system could be responible 
for only a single window (e.g. in the case of a game), or could be in charge of multiple ones (in the case of a level editor). 
The option to create the window as a child of another is therefore given. This method will create an appropriate subclass of 
RenderWindow depending on the API and platform implementation.
<p>After creation, this window can be retrieved using getRenderTarget().</p>
<table cellpadding="4" cellspacing="4" border="0">
<tr class="tablehead">
	<td>
		name
	</td>
	<td>
		The name of the window. Used in other methods later like setRenderTarget and getRenderTarget.
	</td>
</tr>
<tr>
	<td>
		width
	</td>
	<td>
		The width of the new window.
	</td>
</tr>
<tr>
	<td>
		height
	</td>
	<td>
		The height of the new window.
	</td>
</tr>
<tr>
	<td>
		fullScreen
	</td>
	<td>
		Specify true to make the window full screen without borders, title bar or menu bar.
	</td>
</tr>
<tr>
	<td>
		misc
	</td>
	<td>
		String describing the other parameters for the new rendering window. Options are case sensitive. Unrecognised parameters 
		will be ignored silently. These values might be platform dependent, but these are present for all platforms unless indicated 
		otherwise: 
	</td>
</tr>
</table>

<table cellpadding="4" cellspacing="4" border="0">
<tr>
	<td><b>Key</b></td>
	<td><b>Type/Values</b></td>
	<td><b>Default</b></td>
	<td><b>Description</b></td>
	<td><b>Notes</b></td>
</tr>
<tr>
	<td>title</td>
	<td>Any string</td>
	<td>RenderTarget name</td>
	<td>The title of the window that will appear in the title bar </td>
	<td>&nbsp;  </td>
</tr>
<tr>
	<td>colourDepth </td>
	<td>16, 32 </td>
	<td>Desktop depth </td>
	<td>Colour depth of the resulting rendering window; only applies if fullScreen </td>
	<td>Win32 Specific  </td>
</tr>
<tr>
	<td>left </td>
	<td>Positive integers </td>
	<td>Centred </td>
	<td>Screen x coordinate from left </td>
	<td>&nbsp;  </td>
</tr>
<tr>
	<td>top </td>
	<td>Positive integers </td>
	<td>Centred </td>
	<td>Screen y coordinate from left </td>
	<td>&nbsp;  </td>
</tr>
<tr>
	<td>depthBuffer </td>
	<td>true, false </td>
	<td>true </td>
	<td>Use depth buffer </td>
	<td>DirectX9 specific  </td>
</tr>
<tr>
	<td>externalWindowHandle </td>
	<td>
		Win32: HWND as integer<br>
		GLX: poslong:posint:poslong (display*:screen:windowHandle) or poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*)
	</td>
	<td>0 (none) </td>
	<td>External window handle, for embedding the OGRE render in an existing window </td>
	<td>&nbsp;  </td>
</tr>
<tr>
	<td>externalGLControl </td>
	<td>true, false </td>
	<td>false </td>
	<td>
		Let the external window control OpenGL i.e. don't select a pixel format for the window, do not change v-sync and do not swap buffer. 
		When set to true, the calling application is responsible of OpenGL initialization and buffer swapping. It should also create an OpenGL 
		context for its own rendering, <a class="el" href="namespaceOgre.html">Ogre</a> will create one for its use. Then the calling application 
		must also enable Ogre OpenGL context before calling any Ogre function and restore its OpenGL context after these calls. 
	</td>
	<td>OpenGL specific  </td>
</tr>
<tr>
	<td>externalGLContext </td>
	<td>Context as Unsigned Long </td>
	<td>0 (create own context) </td>
	<td>Use an externally created GL context </td>
	<td>OpenGL Specific  </td>
</tr>
<tr>
	<td>parentWindowHandle </td>
	<td>
		Win32: HWND as integer<br>
		GLX: poslong:posint:poslong (display*:screen:windowHandle) or poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*)
	</td>
	<td>0 (none) </td>
	<td>Parent window handle, for embedding the OGRE in a child of an external window </td>
	<td>&nbsp;  </td>
</tr>
<tr>
	<td>macAPI </td>
	<td>String: "cocoa" or "carbon" </td>
	<td>"carbon" </td>
	<td>Specifies the type of rendering window on the Mac Platform. </td>
	<td>&nbsp;  </td>
</tr>
<tr>
	<td>macAPICocoaUseNSView </td>
	<td>bool "true" or "false" </td>
	<td>"false" </td>
	<td>
		On the Mac platform the most diffused method to embed ogre in a custom application is to use the IntefaceBuilder and add to the 
		interface an instance of OgreView. The pointer to this instance is then used as "externalWindowHandle". However, there are cases 
		where you are NOT using the Interface Builder and you get the Cocoa NSView* of an existing interface. For example, this is happens 
		when you want to render into a Java/AWT interface. In short, by setting this flag to "true" the Ogre::Root::createRenderWindow 
		interprets the "externalWindowHandle" as a NSView* instead of an OgreView*. See OgreOSXCocoaView.h
	</td>
	<td>&nbsp;  </td>
</tr>
<tr>
	<td>FSAA </td>
	<td>Positive integer (usually 0, 2, 4, 8, 16) </td>
	<td>0 </td>
	<td>Full screen antialiasing factor </td>
	<td>&nbsp;  </td>
</tr>
<tr>
	<td>FSAAHint </td>
	<td>
		Depends on RenderSystem and hardware. Currently supports:<br>
		"Quality": on systems that have an option to prefer higher AA quality over speed, use it
	</td>
	<td>Blank </td>
	<td>Full screen antialiasing hint </td>
	<td>&nbsp;  </td>
</tr>
<tr>
	<td>displayFrequency </td>
	<td>Refresh rate in Hertz (e.g. 60, 75, 100) </td>
	<td>Desktop vsync rate </td>
	<td>Display frequency rate, for fullscreen mode </td>
	<td>&nbsp;  </td>
</tr>
<tr>
	<td>vsync </td>
	<td>true, false </td>
	<td>false </td>
	<td>Synchronize buffer swaps to monitor vsync, eliminating tearing at the expense of a fixed frame rate </td>
	<td>&nbsp;  </td>
</tr>
<tr>
	<td>vsyncInterval </td>
	<td>1, 2, 3, 4 </td>
	<td>1 </td>
	<td>
		If vsync is enabled, the minimum number of vertical blanks that should occur between renders. For example 
		if vsync is enabled, the refresh rate is 60 and this is set to 2, then the frame rate will be locked at 30.
	</td>
	<td>&nbsp;  </td>
</tr>
<tr>
	<td>border </td>
	<td>none, fixed, resize </td>
	<td>resize </td>
	<td>The type of window border (in windowed mode) </td>
	<td>&nbsp;  </td>
</tr>
<tr>
	<td>outerDimensions </td>
	<td>true, false </td>
	<td>false </td>
	<td>Whether the width/height is expressed as the size of the outer window, rather than the content area </td>
	<td>&nbsp;  </td>
</tr>
<tr>
	<td>useNVPerfHUD </td>
	<td>true, false </td>
	<td>false </td>
	<td>Enable the use of nVidia NVPerfHUD </td>
	<td>&nbsp;  </td>
</tr>
<tr>
	<td>gamma </td>
	<td>true, false </td>
	<td>false </td>
	<td>Enable hardware conversion from linear colour space to gamma colour space on rendering to the window. </td>
	<td>&nbsp;</td>
</tr>
</table>

endrem
	Method createRenderWindow:RenderWindow(name:String, width:Int, Height:Int, fullscreen:Byte = False, misc:String = "")
		Local win:RenderWindow = New RenderWindow
		
		win._ptr = o_createRenderWindow(Self._ptr, name.ToCString(), width, Height, fullscreen, misc.ToCString())
		win._typ = ET_NO_ENTITY
		
		Return win
	End Method
	
rem
bbdoc: Create a SceneManager  instance based on scene type support.
about: Creates an instance of a SceneManager  which supports the scene types identified in the parameter. 
If more than one type of SceneManager  has been registered as handling that combination of scene types, in 
instance of the last one registered is returned. 
<p><b>Note:</b> This method always succeeds, if a specific scene manager is not found, the default implementation is always returned.</p>
<p><b>Parameters:</b> 
<table cellpadding="4" cellspacing="4" border="0">
<tr><td><i>typeMask</i></td><td>A mask containing one or more SceneType flags</td></tr>
<tr><td><i>instanceName</i></td><td>Optional name to given the new instance that is created. If you leave this blank, an auto name 
will be assigned.</td></tr></table>
<p>
<b>SceneTypes:</b><br><i>
ST_GENERIC<br>
ST_EXTERIOR_CLOSE<br>
ST_EXTERIOR_FAR<br>
ST_EXTERIOR_REAL_FAR<br>
ST_INTERIOR
</i></p>
endrem
	Method createSceneManager:SceneManager(typeMask:Int = ST_GENERIC, instanceName:String = "")
		If instanceName = "" Then instanceName = Self.genName("scenemanager_")
		Local scm:SceneManager = New SceneManager
		scm._ptr = o_createSceneManager(Self._ptr, typeMask, instanceName.ToCString())
		scm._typ = ET_NO_ENTITY
		
		Return scm
	End Method
	
rem
bbdoc: Render one frame, with custom frame time information. 
about: Updates all the render targets automatically and then returns, raising frame events before and after - 
all per-frame times are based on the time value you pass in. 
endrem
	Method renderOneFrame:Byte(timeSinceLastFrame:Float = 0.0)
		Return o_renderOneFrame(Self._ptr, timeSinceLastFrame)
	End Method
	
rem
bbdoc: Manually load a Plugin contained in a DLL / DSO.
about: Plugins embedded in DLLs can be loaded at startup using the plugin configuration file specified when you 
create Root (default: plugins.cfg). This method allows you to load plugin DLLs directly in code. The DLL in question 
is expected to implement a dllStartPlugin method which instantiates a Plugin subclass and calls Root::installPlugin. 
It should also implement dllStopPlugin (see Root::unloadPlugin) 
endrem
	Method loadPlugin(plugin:String)
		o_loadPlugin(Self._ptr, plugin.ToCString())
	End Method
	
	
	Method addFrameListener(listener:FrameListener)
		o_addFrameListener(Self._ptr, FrameListener(listener).__listener)
		listener.setFrameStarted(listener.frameStarted)
		listener.setFrameEnded(listener.frameEnded)
	End Method
End Type